package com.study.composite.demo.safe;

import java.util.ArrayList;
import java.util.List;

public class Folder extends Directory {

    private Integer level;
    private List<Directory> dirs;

    public Folder(String name,Integer level) {
        super(name);
        this.level = level;
        this.dirs = new ArrayList<>();
    }

    @Override
    protected void show() {
        System.out.println(this.name);
        for (Directory c:dirs) {
            for (int i = 0; i < this.level; i++) {
                System.out.print("    ");
            }
            System.out.print("+-");
            c.show();
        }
    }

    public void list(){
        for (Directory c:dirs) {
            System.out.println(c.name);
        }
    }

    public void addChild(Directory directory){
        dirs.add(directory);
    }

    public void removeChild(Directory directory){
        dirs.remove(directory);
    }

    public Directory get(int index){
        return dirs.get(index);
    }

}
